package c.j.a.d.b.o;

import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteException;
import android.util.SparseArray;
import c.j.a.d.b.e.b;
import c.j.a.d.b.e.i;
import c.j.a.d.b.e.n;
import c.j.a.d.b.g.a;
import com.ss.android.socialbase.downloader.g.c;
import com.ss.android.socialbase.downloader.notification.DownloadNotificationService;
import java.util.HashSet;
import java.util.Objects;

/* compiled from: DownloadNotificationManager */
public class d {
    public static volatile d b;
    public final SparseArray<c> a = new SparseArray();

    public d() {
        HashSet hashSet = new HashSet();
    }

    public static d a() {
        if (b == null) {
            synchronized (d.class) {
                if (b == null) {
                    b = new d();
                }
            }
        }
        return b;
    }

    public void b(int i) {
        c k = i.a(b.a()).k(i);
        if (k != null) {
            n x = b.x();
            if (x != null && k.D()) {
                k.Q = 3;
                try {
                    x.a(k);
                } catch (SQLiteException e) {
                    e.printStackTrace();
                }
            }
            Object obj = null;
            if (k.D()) {
                int i2 = k.Q;
                Object obj2 = (i2 == 1 || i2 == 3) ? 1 : null;
                if (obj2 != null) {
                    obj = 1;
                }
            }
            if (obj != null) {
                e(k.g0());
            }
        }
    }

    public void c(c cVar) {
        if (cVar != null) {
            synchronized (this.a) {
                this.a.put(cVar.a, cVar);
            }
        }
    }

    public c d(int i) {
        if (i == 0) {
            return null;
        }
        c cVar;
        synchronized (this.a) {
            cVar = (c) this.a.get(i);
        }
        return cVar;
    }

    public void e(int i) {
        if (i != 0) {
            synchronized (this.a) {
                if (((c) this.a.get(i)) != null) {
                    this.a.remove(i);
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.append("removeNotificationId ");
                    stringBuilder.append(i);
                    a.d("DownloaderLogger", stringBuilder.toString());
                }
            }
        }
        if (i != 0) {
            Objects.requireNonNull(a());
            Context a = b.a();
            if (a != null && i != 0) {
                try {
                    Intent intent = new Intent(a, DownloadNotificationService.class);
                    intent.setAction("android.ss.intent.action.DOWNLOAD_NOTIFICATION_CANCEL");
                    intent.putExtra("DOWNLOAD_NOTIFICATION_BUNDLE_EXTRA_ID", i);
                    a.startService(intent);
                } catch (Throwable th) {
                    th.printStackTrace();
                }
            }
        }
    }
}
